import requests
kb_id = 78


def post_rich_content_knowledge_detail(cate):
    response = requests.post(
        url=
        'http://shy-kms.datagrand.cn/api/v1/knowledge_item/knowledge_details',
        headers={
            'Accept': 'application/json, text/plain, */*',
            'Accept-Language': 'zh-CN,zh;q=0.9',
            'AppAuth': 'MTk5NjA4X2ttczAz',
            'Authorization':
            'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3MzQwODIwNDMsIm5iZiI6MTczNDA4MjA0MywianRpIjoiMzFjM2EzZjQtODdmMS00MjJkLWFjOGItMmY2OGE1Y2MwNmQ4IiwiZXhwIjoxNzM0Njg2ODQzLCJpZGVudGl0eSI6WyJ5dWZhbmciLG51bGxdLCJmcmVzaCI6ZmFsc2UsInR5cGUiOiJhY2Nlc3MiLCJ1c2VyX2NsYWltcyI6eyJ1c2VyaWQiOjIyLCJ1c2VybmFtZSI6Inl1ZmFuZyIsImxldmVsIjoiXHU2NjZlXHU5MDFhXHU3NTI4XHU2MjM3IiwidXNlcl9uaWNrbmFtZSI6Ilx1NGY1OVx1NjViOSIsInVzZXJfaWNvbiI6Ii4vYXNzZXRzL2ltYWdlcy9hdmF0YXIuc3ZnIiwidXNlcl9jZW50ZXJfaWQiOm51bGx9fQ.y_WnQDUH-3VowtgPq7U0_Alma7Whu-WQQhHSHwcm16M',
            'Connection': 'keep-alive',
            'KMS-TAG': 'kms',
            'Origin': 'http://shy-kms.datagrand.cn',
            'Referer': 'http://shy-kms.datagrand.cn/',
            'User-Agent':
            'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36 QuarkPC/1.10.5.185',
            'X-APP-ID': '199608',
            'X-APP-NAME': 'kms03',
            'X-SERVICE-TYPE': 'km'
        },
        data={
            'kb_id': str(kb_id),
            'cate_parent_id': str(cate),
            'dir_type': '0'
        })
    if response.status_code == 200 or response.status_code == 201:
        response_data = response.json()
        if response_data['status'] == 200:
            print(f"Post Success: {response_data}")
            return response_data['data']['cate_id'], response_data['data'][
                'knowledge_id']
        else:
            print(f"Error: {response_data}")
            return None, None
    else:
        print(f"HTTP Error: {response.status_code}")
        return None, None


def put_rich_content_knowledge_detail(knowledge_id, name, content, cate_id):
    data = {
        "knowledge_id": int(knowledge_id),
        "name": name,
        "content": content,
        "kb_id": int(kb_id),
        "cate_id": int(cate_id),
        "tag_ids": ""
    }
    response = requests.put(
        url=
        'http://shy-kms.datagrand.cn/api/v1/vpu/knowledge_item/knowledge_draft',
        headers={
            'Accept': 'application/json, text/plain, */*',
            'Accept-Language': 'zh-CN,zh;q=0.9',
            'AppAuth': 'MTk5NjA4X2ttczAz',
            'Authorization':
            'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3MzQwNTg1MjQsIm5iZiI6MTczNDA1ODUyNCwianRpIjoiZGYyMjI3YmQtN2JjNS00YjI3LTk2MWItMDU4YTFiMjgyNWE0IiwiZXhwIjoxNzM0NjYzMzI0LCJpZGVudGl0eSI6WyJhZG1pbiIsbnVsbF0sImZyZXNoIjpmYWxzZSwidHlwZSI6ImFjY2VzcyIsInVzZXJfY2xhaW1zIjp7InVzZXJpZCI6MSwidXNlcm5hbWUiOiJhZG1pbiIsImxldmVsIjoiXHU4ZDg1XHU3ZWE3XHU3YmExXHU3NDA2XHU1NDU4IiwidXNlcl9uaWNrbmFtZSI6ImFkbWluIiwidXNlcl9pY29uIjoiL2ZpbGUvdXBsb2FkL2ljb24vNTkxZDQwM2E5MDg0NWMzZC5wbmciLCJ1c2VyX2NlbnRlcl9pZCI6bnVsbH19.jTWnS4HGz1BFIs_oN4zmdt8W3diOvn04AsjvgXuFKhY',
            'Connection': 'keep-alive',
            'Content-Type': 'application/json',
            'KMS-TAG': 'kms',
            'Origin': 'http://shy-kms.datagrand.cn',
            'Referer': 'http://shy-kms.datagrand.cn/',
            'Use-Progress': 'NO',
            'User-Agent':
            'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36 QuarkPC/1.10.5.185',
            'X-APP-ID': '199608',
            'X-APP-NAME': 'kms03',
            'X-SERVICE-TYPE': 'km'
        },
        json=data)
    if response.status_code == 200 or response.status_code == 201:
        response_data = response.json()
        if response_data['status'] == 200:
            print(f"Success: {name}")
            return True
        else:
            print(f"Error: {name}")
            print(f"Error: {response_data}")
            return False
    else:
        print(f"HTTP Error: {name}")
        print(f"HTTP Error: {response.status_code}")
        return False


def approve(knowledge_id):
    response = requests.post(
        url='http://shy-kms.datagrand.cn/api/v1/knowledge_approve/approve',
        headers={
            'Accept': 'application/json, text/plain, */*',
            'Accept-Language': 'zh-CN,zh;q=0.9',
            'AppAuth': 'MTk5NjA4X2ttczAz',
            'Authorization':
            'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3MzQxMDYxMTQsIm5iZiI6MTczNDEwNjExNCwianRpIjoiNDYzNWU5NmMtNjg1YS00MWViLTkxYzYtZTk1NmExNmNjYzQ0IiwiZXhwIjoxNzM0NzEwOTE0LCJpZGVudGl0eSI6WyJ5dWZhbmciLG51bGxdLCJmcmVzaCI6ZmFsc2UsInR5cGUiOiJhY2Nlc3MiLCJ1c2VyX2NsYWltcyI6eyJ1c2VyaWQiOjIyLCJ1c2VybmFtZSI6Inl1ZmFuZyIsImxldmVsIjoiXHU2NjZlXHU5MDFhXHU3NTI4XHU2MjM3IiwidXNlcl9uaWNrbmFtZSI6Ilx1NGY1OVx1NjViOSIsInVzZXJfaWNvbiI6Ii4vYXNzZXRzL2ltYWdlcy9hdmF0YXIuc3ZnIiwidXNlcl9jZW50ZXJfaWQiOm51bGx9fQ.9PZBSnJzTJvBkOlS3XTjloMUo4zeT0i5tqda8ohbZ0g',
            'Connection': 'keep-alive',
            'Content-Type': 'application/json',
            'KMS-TAG': 'kms',
            'Origin': 'http://shy-kms.datagrand.cn',
            'Referer': 'http://shy-kms.datagrand.cn/',
            'User-Agent':
            'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36 QuarkPC/1.10.5.185',
            'X-APP-ID': '199608',
            'X-APP-NAME': 'kms03',
            'X-SERVICE-TYPE': 'km'
        },
        json={"knowledge_id": knowledge_id})
    if response.status_code == 200 or response.status_code == 201:
        response_data = response.json()
        if response_data['status'] == 200:
            print(f"approve Success")
        else:
            print(f"Error: {response_data}")
    else:
        print(f"HTTP Error: {response.status_code}")

